//
//  SEHospitalDetailViewModel.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/5/9.
//

import UIKit

class SEHospitalDetailViewModel: SEBaseViewModel {

    var model = SEHospitalDetailModel()

    var hospitalListItem: SEHospitalListItem {
        return SEHospitalListItem(id: model.hisHospitalId,
                                  orgId: model.id,
                                  name: model.name,
                                  address: model.addr,
                                  level: model.hospitalJb)
    }

    func doctorModel(indexPath: IndexPath) -> SEDoctorDetail {
        return model.recommentDoctors[indexPath.row]
    }

    func numberOfRows(section: Int) -> Int {
        switch section {
        case 2: return model.recommentDoctors.count
        default: return 1
        }
    }

    var followedHandler: ((SEHttpStatus) -> Void)?

    /// 医院详情
    func requestHospitalDetail() {
        SEHttpManager.shared.request(SEHospitalAPI.hospitalDetail(id: model.id), model: SEHospitalDetailModel.self, withLoading: true) { model, status in
            switch status {
            case .success:
                self.model = model ?? self.model
            default:
                break
            }
            self.updateData?(status)
        }
    }

    /// 关注医院
    func requestFollowedHospital() {
        SEHttpManager.shared.requestForAny(SEProfileAPI.followedDoctorOrHospital(userId: UserDefaults.userId, targetId: model.id, role: "1"), withLoading: true) { result, status in
            self.followedHandler?(status)
        }
    }

}
